﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Dispatcher;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Runtime.Serialization;

namespace IAOI.Platform.WCF.WCF.Fault
{



    public class ErrorHandler : IErrorHandler
    {
        public bool HandleError(Exception error)
        {
            Console.WriteLine("HandleError called.");
            // Returning true indicates you performed your behavior.
            return true;

        }

        public void ProvideFault(Exception error,
            System.ServiceModel.Channels.MessageVersion version,
            ref System.ServiceModel.Channels.Message fault)
        {
            Console.WriteLine("ProvideFault called. Converting Exception to GreetingFault....");
            FaultException<GreetingFault> fe
              = new FaultException<GreetingFault>(new GreetingFault(error.Message));
            MessageFault messagefault = fe.CreateMessageFault();
            fault = Message.CreateMessage(
              version,
              messagefault,
              "http://microsoft.wcf.documentation/ISampleService/SampleMethodGreetingFaultFault"
            );

        }
    }
}
